home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Human Interface Toolbox / GetDragHiliteColor / Application.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.4 KB  |  206 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Application.c
  3.  
  4.     Contains:    This shows how to obtain the color that the Drag Manager uses to
  5.                 hilite regions when ShowDragHilite is called.  Check out GetDragHilite.c
  6.                 for the code.  
  7.  
  8.                 Please note this is only how it's done presently.  Since it is undocumented
  9.                 it can and will change in the future.
  10.  
  11.     Written by: Nitin Ganatra    
  12.  
  13.     Copyright:    Copyright © 1994-1999 by Apple Computer, Inc., All Rights Reserved.
  14.  
  15.                 You may incorporate this Apple sample source code into your program(s) without
  16.                 restriction. This Apple sample source code has been provided "AS IS" and the
  17.                 responsibility for its operation is yours. You are not permitted to redistribute
  18.                 this Apple sample source code as "Apple sample source code" after having made
  19.                 changes. If you're going to re-distribute the source, we require that you make
  20.                 it clear in the source that the code was descended from Apple sample source
  21.                 code, but that you've made changes.
  22.  
  23.     Change History (most recent first):
  24.                 8/6/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  25.                 
  26.  
  27. */
  28.  
  29. #include <QuickDraw.h>
  30. #include <Dialogs.h>
  31. #include <Fonts.h>
  32. #include <Processes.h>
  33. #include <TextEdit.h>
  34. #include <Events.h>
  35. #include <Menus.h>
  36. #include <Memory.h>
  37. #include <Errors.h>
  38. #include <ToolUtils.h>
  39. #include <Resources.h>
  40.  
  41.  
  42. void InitApplication(void);
  43. void MyCreateNewWindow(void);
  44. void MainEventLoop(void);
  45. void MenuCommand(long whaHappened);
  46. void DoAboutBox(void);
  47.  
  48. void PreEventLoop(void);
  49. void PostEventLoop(void);
  50. pascal void DrawWindowContent(short, short, GDHandle, long);
  51. void DrawIt(WindowPtr win);
  52. void DoUpdate(WindowPtr thisWindow);
  53.  
  54. static Boolean gDone;
  55.  
  56.  
  57. /*-------------------------------------------------------------------------------------*/
  58.  
  59. void main()
  60. {
  61.  
  62.     InitApplication();
  63.     PreEventLoop();
  64.     MainEventLoop();
  65. }
  66.  
  67.  
  68. /*-------------------------------------------------------------------------------------*/
  69.  
  70. void InitApplication()
  71. {
  72.     Handle theMenu;
  73.  
  74.     // Toolbox initialization
  75.     MaxApplZone();
  76.     InitGraf(&qd.thePort);
  77.     InitFonts();
  78.     InitWindows();
  79.     InitMenus();
  80.     TEInit();
  81.     InitDialogs(nil);
  82.     InitCursor();
  83.     FlushEvents(0,everyEvent);
  84.     
  85.     // Application initialization
  86.     gDone = false;
  87.     
  88.     theMenu = GetNewMBar(128);
  89.     if ( theMenu == nil )
  90.         goto MenuStuffFailed;
  91.  
  92.     SetMenuBar(theMenu);
  93.     AppendResMenu(GetMenuHandle(128), 'DRVR');
  94.     DrawMenuBar();
  95.  
  96.     return;
  97.     
  98. MenuStuffFailed:
  99.     // If the menu stuff failed, something just ain't right (most likely some 
  100.     // resources are missing.
  101.     gDone = true;
  102.     return;
  103.  
  104. }
  105.  
  106.  
  107. /*-------------------------------------------------------------------------------------*/
  108.  
  109. void DoAboutBox()
  110. {
  111.     (void) Alert(128, nil);
  112. }
  113.  
  114.  
  115. /*-------------------------------------------------------------------------------------*/
  116.  
  117. void MainEventLoop()
  118. {
  119.     EventRecord        theEvent;
  120.     WindowPtr        thisWindow;
  121.     short            clickArea;
  122.     Rect            screenRect;
  123.     long            menuResult;
  124.     char            charCode;
  125.  
  126.     while ( !gDone )
  127.     {
  128.         if ( WaitNextEvent(everyEvent, &theEvent, 0, nil) )
  129.         {
  130.             switch (theEvent.what)
  131.             {
  132.                 case mouseDown:
  133.                     clickArea = FindWindow(theEvent.where, &thisWindow);
  134.                     
  135.                     if (clickArea == inDrag)
  136.                     {
  137.                         screenRect = (**GetGrayRgn()).rgnBBox;
  138.                         DragWindow(thisWindow, theEvent.where, &screenRect);
  139.                     }
  140.                     else if ( clickArea == inContent )
  141.                     {
  142.                         if ( thisWindow != FrontWindow() )
  143.                             SelectWindow(thisWindow);
  144.                     }
  145.                     else if (clickArea == inGoAway)
  146.                     {
  147.                         if ( TrackGoAway(thisWindow, theEvent.where) )
  148.                             gDone = true;
  149.                     }
  150.                     else if ( clickArea == inMenuBar ) 
  151.                     {
  152.                         menuResult = MenuSelect(theEvent.where);
  153.                         if ( (menuResult  >> 16) != 0 )
  154.                         {
  155.                             MenuCommand(menuResult);
  156.                             HiliteMenu(0);
  157.                         }
  158.                     }
  159.                     break;
  160.                 case keyDown:
  161.                     charCode = theEvent.message & charCodeMask;
  162.  
  163.                     if ( (theEvent.modifiers & cmdKey) != 0 ) 
  164.                     {    
  165.                         menuResult = MenuKey(charCode);
  166.                 
  167.                         if ( (menuResult  >> 16) != 0 )
  168.                             MenuCommand(menuResult);
  169.                             
  170.                     } 
  171.                     break;
  172.                 case updateEvt:
  173.                     thisWindow = (WindowPtr)theEvent.message;    
  174.                     DoUpdate(thisWindow);
  175.                 
  176.                     break;
  177.                 
  178.             }
  179.         }
  180.     }
  181. }
  182.  
  183.  
  184.  
  185. /*-------------------------------------------------------------------------------------*/
  186.  
  187. void MenuCommand(long whaHappened)
  188. {
  189.     short    menuID, menuItem;
  190.     
  191.     menuID = (whaHappened >> 16);
  192.     menuItem = (whaHappened & 0xFFFF);
  193.     
  194.     if ( menuID == 128 )
  195.     {
  196.         if ( menuItem == 1)
  197.             DoAboutBox();
  198.     }
  199.     else if ( menuID == 129 )
  200.     {
  201.         if (menuItem == 1)
  202.             gDone = true;
  203.     }
  204. }
  205.  
  206.